package com.drcoffee.drcoffeemall.mapper;

import com.drcoffee.drcoffeemall.entry.InvoiceRecords;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

@Mapper
@Repository
public interface InvoiceMapper {

    @Insert("INSERT INTO invoice_records VALUES (#{code},#{user_account},#{order_code},CURRENT_TIMESTAMP,#{Invoice_date},#{invoice_type},#{title_type},#{amount},#{invoice_title},#{tax_number},#{registered_address},#{registered_phone},#{bank_of_deposit},#{bank_account},#{file_path},#{current_step})")
    void insertInvoiceRecords(InvoiceRecords invoiceRecords);


    @Select("SELECT invoice_type,title_type,amount,invoice_title,tax_number,registered_address,registered_phone,bank_of_deposit,bank_account FROM invoice_records WHERE user_account = #{user_account} ORDER BY apply_for_date DESC LIMIT 1")
    InvoiceRecords getLastInvoice(String user_account);

    @Select("SELECT COUNT(0) FROM invoice_records WHERE order_code = #{orderCode}")
    Integer getInvoiceExistByOrderCode(String orderCode);

    @Select("SELECT CONCAT(b.o_file_path, b.folder, a.file_path) as file_path " +
            "FROM invoice_records a, t_file_path b " +
            "WHERE a.order_code = #{order_code} " +
            "AND b.bsh_one = 'L' " +
            "AND b.bsh_two = 1")
    String getInvoicePathByCode(String order_code);

}
